| += (Add By Value) The add by value operator is also known as the "Addition Assignment" operator. It is used to add the value on the right of the add by value operator to the value on the left of the add by value operator, the result of which replaces the variable value on the left of the operator. If neither of the operand values are strings or numbers, they will be converted to numbers. This operator can also be used for string concatentation. That is, the joining of two words or numeric characters (strings) together to form one string. Again, the operand on the right is concatenated to the operand on the left, and the left operand is overwritten with the new value. If one of the operands is not a string, it is converted to a string, then concatenated. syntax: variable += value EXAMPLE num = 50; stringValue = new string("50"); num += 10; stringValue += 10; document.write( "The num variable now equals " + num); document.write("The stringValue variable now equals " + stringValue); In this example, the first variable, num, is loaded with the number 50. The second variable, stringValue, (which is a string value, hence the quotes), is then also loaded with the number 50. The two instances of the add by value operand add a value of ten to each variable. The document.write statements then write the contents of the two variables, along with some text, to the browser screen. |